﻿/**  版本信息模板在安装目录下，可自行修改。
* T_BH.cs
*
* 功 能： N/A
* 类 名： T_BH
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017/6/3 13:45:11   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using SYDZ.WMS.DBUtility;//Please add references
namespace WMSAML.Warehouse.DAL
{
	/// <summary>
	/// 数据访问类:T_BH
	/// </summary>
	public partial class T_BH
	{
		public T_BH()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("NID", "T_BH"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int NID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_BH");
			strSql.Append(" where NID=@NID");
			SqlParameter[] parameters = {
					new SqlParameter("@NID", SqlDbType.Int,4)
			};
			parameters[0].Value = NID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(WMSAML.Warehouse.Model.T_BH model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_BH(");
			strSql.Append("BH_Date,BH_Machine,BH_NUM,BH_userName,BH_usertime,BK01,BK02,BK03,BK04,BK05,BK06)");
			strSql.Append(" values (");
			strSql.Append("@BH_Date,@BH_Machine,@BH_NUM,@BH_userName,@BH_usertime,@BK01,@BK02,@BK03,@BK04,@BK05,@BK06)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@BH_Date", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_Machine", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_NUM", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_userName", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_usertime", SqlDbType.DateTime),
					new SqlParameter("@BK01", SqlDbType.NVarChar,50),
					new SqlParameter("@BK02", SqlDbType.NVarChar,50),
					new SqlParameter("@BK03", SqlDbType.NVarChar,50),
					new SqlParameter("@BK04", SqlDbType.NVarChar,50),
					new SqlParameter("@BK05", SqlDbType.NVarChar,50),
					new SqlParameter("@BK06", SqlDbType.NVarChar,50)};
			parameters[0].Value = model.BH_Date;
			parameters[1].Value = model.BH_Machine;
			parameters[2].Value = model.BH_NUM;
			parameters[3].Value = model.BH_userName;
			parameters[4].Value = model.BH_usertime;
			parameters[5].Value = model.BK01;
			parameters[6].Value = model.BK02;
			parameters[7].Value = model.BK03;
			parameters[8].Value = model.BK04;
			parameters[9].Value = model.BK05;
			parameters[10].Value = model.BK06;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(WMSAML.Warehouse.Model.T_BH model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_BH set ");
			strSql.Append("BH_Date=@BH_Date,");
			strSql.Append("BH_Machine=@BH_Machine,");
			strSql.Append("BH_NUM=@BH_NUM,");
			strSql.Append("BH_userName=@BH_userName,");
			strSql.Append("BH_usertime=@BH_usertime,");
			strSql.Append("BK01=@BK01,");
			strSql.Append("BK02=@BK02,");
			strSql.Append("BK03=@BK03,");
			strSql.Append("BK04=@BK04,");
			strSql.Append("BK05=@BK05,");
			strSql.Append("BK06=@BK06");
			strSql.Append(" where NID=@NID");
			SqlParameter[] parameters = {
					new SqlParameter("@BH_Date", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_Machine", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_NUM", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_userName", SqlDbType.NVarChar,50),
					new SqlParameter("@BH_usertime", SqlDbType.DateTime),
					new SqlParameter("@BK01", SqlDbType.NVarChar,50),
					new SqlParameter("@BK02", SqlDbType.NVarChar,50),
					new SqlParameter("@BK03", SqlDbType.NVarChar,50),
					new SqlParameter("@BK04", SqlDbType.NVarChar,50),
					new SqlParameter("@BK05", SqlDbType.NVarChar,50),
					new SqlParameter("@BK06", SqlDbType.NVarChar,50),
					new SqlParameter("@NID", SqlDbType.Int,4)};
			parameters[0].Value = model.BH_Date;
			parameters[1].Value = model.BH_Machine;
			parameters[2].Value = model.BH_NUM;
			parameters[3].Value = model.BH_userName;
			parameters[4].Value = model.BH_usertime;
			parameters[5].Value = model.BK01;
			parameters[6].Value = model.BK02;
			parameters[7].Value = model.BK03;
			parameters[8].Value = model.BK04;
			parameters[9].Value = model.BK05;
			parameters[10].Value = model.BK06;
			parameters[11].Value = model.NID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int NID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_BH ");
			strSql.Append(" where NID=@NID");
			SqlParameter[] parameters = {
					new SqlParameter("@NID", SqlDbType.Int,4)
			};
			parameters[0].Value = NID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string NIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_BH ");
			strSql.Append(" where NID in ("+NIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public WMSAML.Warehouse.Model.T_BH GetModel(int NID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 NID,BH_Date,BH_Machine,BH_NUM,BH_userName,BH_usertime,BK01,BK02,BK03,BK04,BK05,BK06 from T_BH ");
			strSql.Append(" where NID=@NID");
			SqlParameter[] parameters = {
					new SqlParameter("@NID", SqlDbType.Int,4)
			};
			parameters[0].Value = NID;

			WMSAML.Warehouse.Model.T_BH model=new WMSAML.Warehouse.Model.T_BH();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public WMSAML.Warehouse.Model.T_BH DataRowToModel(DataRow row)
		{
			WMSAML.Warehouse.Model.T_BH model=new WMSAML.Warehouse.Model.T_BH();
			if (row != null)
			{
				if(row["NID"]!=null && row["NID"].ToString()!="")
				{
					model.NID=int.Parse(row["NID"].ToString());
				}
				if(row["BH_Date"]!=null)
				{
					model.BH_Date=row["BH_Date"].ToString();
				}
				if(row["BH_Machine"]!=null)
				{
					model.BH_Machine=row["BH_Machine"].ToString();
				}
				if(row["BH_NUM"]!=null)
				{
					model.BH_NUM=row["BH_NUM"].ToString();
				}
				if(row["BH_userName"]!=null)
				{
					model.BH_userName=row["BH_userName"].ToString();
				}
				if(row["BH_usertime"]!=null && row["BH_usertime"].ToString()!="")
				{
					model.BH_usertime=DateTime.Parse(row["BH_usertime"].ToString());
				}
				if(row["BK01"]!=null)
				{
					model.BK01=row["BK01"].ToString();
				}
				if(row["BK02"]!=null)
				{
					model.BK02=row["BK02"].ToString();
				}
				if(row["BK03"]!=null)
				{
					model.BK03=row["BK03"].ToString();
				}
				if(row["BK04"]!=null)
				{
					model.BK04=row["BK04"].ToString();
				}
				if(row["BK05"]!=null)
				{
					model.BK05=row["BK05"].ToString();
				}
				if(row["BK06"]!=null)
				{
					model.BK06=row["BK06"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select NID,BH_Date,BH_Machine,BH_NUM,BH_userName,BH_usertime,BK01,BK02,BK03,BK04,BK05,BK06 ");
			strSql.Append(" FROM T_BH ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" NID,BH_Date,BH_Machine,BH_NUM,BH_userName,BH_usertime,BK01,BK02,BK03,BK04,BK05,BK06 ");
			strSql.Append(" FROM T_BH ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_BH ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.NID desc");
			}
			strSql.Append(")AS Row, T.*  from T_BH T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_BH";
			parameters[1].Value = "NID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

